package com.github.wxiaoqi.security.biz.biz;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.wxiaoqi.security.biz.entity.BhIndustry;
import com.github.wxiaoqi.security.biz.entity.BhTask;
import com.github.wxiaoqi.security.biz.mapper.BhIndustryMapper;
import com.github.wxiaoqi.security.biz.mapper.BhTaskMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.util.EntityUtils;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * 行业表   存储行业信息
 *
 * @author Mr.AG
 * @email 463540703@qq.com
 * @date 2018-05-16 10:29:09
 */
@Service
public class BhIndustryBiz extends BaseBiz<BhIndustryMapper,BhIndustry> {
	//@Autowired
	//private BhIndustryMapper mapper;
	@Autowired
	private BhTaskMapper bhTaskMapper;
	
	public List<Map<String, Object>> queryAll() throws Exception{
		List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
		BhIndustry industry = new BhIndustry();
		industry.setParentid("-1");
		List<BhIndustry> list =  mapper.select(industry);
		for (BhIndustry bhIndustry : list) {
			Map<String, Object> chMap = EntityUtils.beanToMap(bhIndustry);
			BhIndustry in = new BhIndustry();
			in.setParentid(bhIndustry.getId());
			List<BhIndustry> childrenList = mapper.select(in);
			chMap.put("children", childrenList);
			listMap.add(chMap);
		}
		return listMap;
	}
	/**
	 * 关注的行业匹配悬赏
	 */
	public int queryIndustryRewardCount(Map<String, Object> req) throws Exception{
		String attentionIndustry = (String) req.get("attentionIndustry");
		if(null == attentionIndustry || "".equals(attentionIndustry)){
			return 0;
		}
        String[] industrys = attentionIndustry.split(",");
		List<String> list = new ArrayList<String>(Arrays.asList(industrys));
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("companyIndustry", attentionIndustry);
		int amount = bhTaskMapper.queryTaskIndustry(list);
        return amount;
	}
}